package cn.tramy.pinxian.common.util.func


import java.util.*

/**
 * Created  on 16/8/29.
 */
class ConditionalExceptionFunc(private val conditionFunc: () -> Boolean) : CommonFunc {
    private lateinit var exceptionFunc: () -> Throwable

    fun exception(exceptionFunc: () -> Throwable): ConditionalExceptionFunc {
        Objects.requireNonNull(exceptionFunc)
        this.exceptionFunc = exceptionFunc
        return this
    }

    override fun execute() {
        val conditional = this.conditionFunc()
        if (conditional) {
            throw exceptionFunc()
        }
    }
}
